/*! \file Driver.cpp
 *	\brief 
 *
 *	created:	2009/11/12
 *	created:	12:11:2009   16:33
 *	filename: 	c:\src\main\libs\gd_dx9\Driver.cpp
 *	file path:	c:\src\main\libs\gd_dx9
 *	file base:	Driver
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
 
#include "StdAfx.h"
#include "Driver.h"

#include <app_win/Window.h>
#include <core/exception.h>

#include "Device.h"

#pragma comment(lib, "d3d9.lib")

namespace tt{
namespace gd_dx9{

Driver::Driver(void)
: m_pD3D( Direct3DCreate9( D3D_SDK_VERSION ) )
{
	if( NULL == m_pD3D )
		TT_THROW( TEXT("Direct3DCreate9 create failed!") );
}

Driver::~Driver(void)
{
}


utils::COMPointer<IDirect3D9>& Driver::d3dDriver()
{
	return m_pD3D;
}

SharedPtr<gd::Device> Driver::onCreateDevice(const SharedPtr<app::Window>& window)
{
	SharedPtr<app_win::Window> window_win = dynamic_pointer_cast<app_win::Window>(window);
	if(!window_win)
		TT_THROW(TEXT("Window is not descendant of app_win::Window"));
	return SharedPtr<gd::Device>(new Device(this, window_win));;
}

} //namespace gd_dx9
} //namespace tt
